home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "Module1"
- Option Explicit
-
- '' The following constants are defined in ODBCINST.H in MSVC++ 2.2
- Global Const ODBC_ADD_DSN = 1 ' Add data source
- Global Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
- Global Const ODBC_REMOVE_DSN = 3 ' Remove data source
-
- '' This function is part of ODBCCP32.DLL and is used to setup a data source.
- '' If the first arg is NULL, no dialog will be shown when the function
- '' is called. The second arg may be one of ODBC_ADD_DSN, ODBC_CONFIG_DSN,
- '' or ODBC_REMOVE_DSN. The third arg is the Driver description used instead
- '' of the physical driver name. The last arg is a set of keyword value
- '' pairs that setup the data source. See the ODBC API help file ODBC20.HLP
- '' distributed with MSVC++ 2.0 for more info.
-
- Declare Function SQLConfigDataSource Lib "odbccp32.dll" (ByVal hWndParent&, ByVal fRequest%, ByVal lpszDriver$, ByVal lpszAttributes$) As Boolean
-
- Sub MakeYellowGreenBars(SS As Object, whichSheet&)
- '' Formats rows as alternating yellow and green bars from 1 to LastRow
- '' On the given sheet. If you make this for only the cells with data
- '' you will be adding a format for each cell which will use much
- '' more RAM (flag + 2 colors + pattern) * num cells
-
- Dim r&, c&
-
- c = -1
- With SS
- .Sheet = whichSheet
- .SetSelection 1, c, 1, c
- For r = 3 To .LastRow Step 2
- .AddSelection r, c, r, c
- Next r
- .SetPattern 4, .PaletteEntry(4), .PaletteEntry(2)
-
- .SetSelection 2, c, 2, c
- For r = 4 To .LastRow Step 2
- .AddSelection r, c, r, c
- Next r
- .SetPattern 4, .PaletteEntry(6), .PaletteEntry(2)
- .Selection = "A1"
- End With
-
- End Sub
-
- Sub SetRowColCalc(SS As Object, wsFunc$, startRow&, endRow&, startCol&, endCol&)
- '' Assumes a rectangle of data and sets formulas in the col to
- '' the right of the data that is the given function over the given
- '' range. Inserts formulas from row 1 to LastRow.
-
- Dim formula$, savedSelection$
-
- With SS
- Let savedSelection = .Selection
-
- '' Column formula
- Let formula = wsFunc & "(" & .FormatRCNr(startRow, startCol, False) _
- & ":" & .FormatRCNr(startRow, endCol, False) & ")"
- .SetSelection startRow, endCol + 1, startRow, endCol + 1
- .formula = formula
- .SetSelection startRow, endCol + 1, endRow, endCol + 1
- .EditCopyDown
-
- '' Row formula
- Let formula = wsFunc & "(" & .FormatRCNr(startRow, startCol, False) _
- & ":" & .FormatRCNr(endRow, startCol, False) & ")"
- .SetSelection endRow + 1, startCol, endRow + 1, startCol
- .formula = formula
- .SetSelection endRow + 1, startCol, endRow + 1, endCol + 1
- .EditCopyRight
-
- .Selection = savedSelection
- End With
-
- End Sub
-
- Sub FormatSalesCrossTab(SS As Object, whichSheet&)
- '' Formats rows as yellow and green bars with the right column
- '' and bottom row grey with a single border on the inside.
-
- Dim savedSelection$
-
- With SS
- Let savedSelection = .Selection
- Call MakeYellowGreenBars(SS, whichSheet)
-
- '' Format column
- .SetSelection -1, .LastCol, -1, .LastCol
- .SetPattern 4, .PaletteEntry(15), .PaletteEntry(2)
- .SetBorder -1, 1, 5, -1, -1, 0, 0, 0, 0, 0, 0
-
- '' Format row
- .SetSelection .LastRow, -1, .LastRow, -1
- .SetPattern 4, .PaletteEntry(15), .PaletteEntry(2)
- .SetBorder -1, -1, -1, 1, 5, 0, 0, 0, 0, 0, 0
-
- '' Now set an outline and max RC
- .MaxRow = .LastRow
- .MaxCol = .LastCol
-
- '' Now resize all cells so they can display their data
- .SetColWidthAuto -1, -1, -1, -1, True
-
- .Selection = savedSelection
- End With
-
- End Sub
- Sub Fetch(SS As Object, whichSheet&, startRow&, startCol&, dsName$, query$, _
- setColNames As Boolean, setColFormats As Boolean, setColWidths As Boolean, _
- setMaxRC As Boolean)
- '' Performs the query and places on wheet with given options
-
- On Error GoTo FetchError
- Dim returnCode%
-
- With SS
- .Sheet = whichSheet
- .ODBCConnect dsName, True, returnCode
- .ODBCQuery query, startRow, startCol, False, setColNames, _
- setColFormats, setColWidths, setMaxRC, returnCode
- .ODBCDisconnect
- End With
-
- Exit Sub
- FetchError:
- MsgBox Error
- End Sub
-
- Sub NameAndFormatColumn(SS As Object, whichSheet&, col&, what$, numFormat$)
- '' Sets the Column text of the specified sheet to to what and
- '' then sets the col width to accommodate.
-
- Dim savedSheet&, savedSelection$
-
- With SS
- savedSheet = .Sheet
- savedSelection = .Selection
- .Sheet = whichSheet
- .ColText(col) = what
- .SetColWidthAuto -1, col, -1, col, True
- .SetSelection -1, col, -1, col
- .NumberFormat = numFormat
- .Sheet = savedSheet
- .Selection = savedSelection
- End With
-
- End Sub
-
- Sub NameAndFormatRow(SS As Object, whichSheet&, row&, what$, numFormat$)
- '' Sets the Row text of the specified sheet to to what and
- '' then sets the row header width to accommodate.
-
- Dim savedSheet&, savedSelection$
-
- With SS
- savedSheet = .Sheet
- savedSelection = .Selection
- .Sheet = whichSheet
- .RowText(row) = what
- .SetSelection row, -1, row, -1
- .NumberFormat = numFormat
- .Sheet = savedSheet
- .Selection = savedSelection
- End With
-
-
- End Sub
-